package com.fmjr.web.ftlvariables;

import com.fmjr.common.util.SpringUtil;
import com.fmjr.sys.sysUser.bean.SysUser;
import com.fmjr.sys.sysUser.service.ISysUserService;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

@Service
public class UserDirective implements TemplateDirectiveModel{
	
	private ISysUserService sysUserService = (ISysUserService) SpringUtil.getBean("sysUserService");

	@Override
	public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
		Long userId = 0l;  
        if(params.get("sysUser") != null && !params.get("sysUser").toString().equals("")){  
        	userId = Long.parseLong(params.get("sysUser").toString()); 
        	SysUser sysUser = sysUserService.selectSysUserById(userId);
        	env.getOut().write(sysUser!=null?sysUser.getUserName():"");
        }  
	}
   
}  